package com.yuehuanghun.framework.exception;

import java.util.HashMap;
import java.util.Map;

import org.springframework.http.HttpStatus;

public class ValidateException extends PlatformException {
	private static final long serialVersionUID = 1L;
	private static final int DEFAULT_CODE = HttpStatus.BAD_REQUEST.value();
	
	private Map<String, Object> errors;
	public ValidateException(){
		super("参数不正确");
	}
	/**
	 * code = 400
	 * @param message
	 */
	public ValidateException(String message){
		super(DEFAULT_CODE, message);
	}
	
	public ValidateException(int code, String message){
		super(code, message);
	}
	
	public ValidateException(int code, String message, Throwable ex){
		super(code, message, ex);
	}
	
	public ValidateException(String message, Throwable ex){
		super(message, ex);
	}
	
	public ValidateException(Throwable ex){
		super(ex);
	}
	
	public ValidateException addError(String key, Object value){
		if(errors == null){
			errors = new HashMap<>();
		}
		errors.put(key, value);
		return this;
	}
	
	public Map<String, Object> getErrors(){
		return errors;
	}
}
